package com.gemme.gemme.wode;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.core.widget.NestedScrollView;

import com.alibaba.fastjson.JSON;
import com.bumptech.glide.Glide;
import com.gemme.gemme.MainActivity;
import com.gemme.gemme.R;
import com.gemme.gemme.adapter.DataBean;
import com.gemme.gemme.adapter.ImageAdapter;
import com.gemme.gemme.gwc.ConfirmOrderActivity;
import com.gemme.gemme.login.Constant;
import com.gemme.gemme.manager.DataManager;
import com.gemme.gemme.manager.DataPares;
import com.gemme.gemme.util.DpUtil;
import com.gemme.gemme.util.PCUtil;
import com.gemme.gemme.util.SPUtil;
import com.gemme.gemme.util.StrUtil;
import com.gemme.gemme.view.GuigeDialog;
import com.gemme.gemme.view.GuigeSingleView;
import com.gemme.gemme.view.OnChangeLIstener;
import com.gemme.gemme.view.PriceView;
import com.gemme.gemme.view.ProductDetailView;
import com.gemme.gemme.view.ProductIntroduceView;
import com.gemme.gemme.view.ProductShaidanView;
import com.gemme.gemme.view.ProductTuijianView;
import com.gemme.gemme.view.ShareDialog;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.tabs.TabLayout;
import com.hyphenate.chat.ChatClient;
import com.hyphenate.helpdesk.easeui.util.IntentBuilder;
import com.youth.banner.Banner;
import com.youth.banner.config.IndicatorConfig;
import com.youth.banner.indicator.CircleIndicator;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class ProductNewActivity extends Activity implements View.OnClickListener {
    public static final String TAG = "ProductNewActivity";
    Context context = ProductNewActivity.this;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //透明状态栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//        //透明导航栏
//        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setNavigationBarColor(Color.parseColor("#000000"));
        }

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_product_new);
        initTop();
        initIntent();
        initView();
//        initBanner();
        initData();
        getAndroiodScreenProperty();
        controlScroll();
//        testAddGwc();
    }




    long id;
    long brandId;
    private void initIntent() {
        try {
            Intent intent = getIntent();

            id = intent.getLongExtra("id",-1);
            brandId = intent.getLongExtra("brandId",-1);

        }catch (Exception e){

        }
    }

    ArrayList<DataBean> dataBeans = new ArrayList<>();
    private void initBanner() {
//        DataBean.getTestData()


//        CoordinatorLayout

        for (int i = 0; i < picList.size(); i++) {
            DataBean dataBean = new DataBean();
            dataBean.setImageRes(picList.get(i));
            dataBeans.add(dataBean);
        }
        ImageAdapter imageAdapter = new ImageAdapter(dataBeans);
        Banner banner =  findViewById(R.id.banner);
        banner
//                .addBannerLifecycleObserver(this)//添加生命周期观察者
                .setAdapter(imageAdapter)
                .setIndicator(new CircleIndicator(this))
//                .setIndicator(new RectangleIndicator(this))
                .isAutoLoop(false)
//                .setIndicatorMargins(new IndicatorConfig.Margins(0,0,0, DpUtil.dp2px(this,50)))
                .setIndicatorMargins(new IndicatorConfig.Margins(0,0,0, DpUtil.dp2px(this,100)))
                .setIndicatorNormalColor(Color.parseColor("#ff9d2c2f"))
                .setIndicatorSelectedColor(Color.parseColor("#FFFFFFFF"))
                .start()
        ;

        imageAdapter.setOnChangeLIstener(new OnChangeLIstener() {
            @Override
            public void onChangeLIstener() {
                PCUtil.previewPic(ProductNewActivity.this,picList,false);
            }
        });

    }
    NestedScrollView svscrollouter;
    ProductIntroduceView introduceView;
    ProductShaidanView shaidanView;
    ProductDetailView detailView;
    ProductTuijianView productTuijianView;
    ImageView iv_share;
    ImageView iv_gwc;
    ImageView iv_xyd;
    GuigeDialog guigeDialog;
    TextView tv_name;
    TextView tv_price;
    TextView tv_price_two;
    PriceView priceViewnum;
    ImageView iv_kefu;
    private void initView() {
        initTabLayout();
        AppBarLayout appBarlayout = findViewById(R.id.appBarlayout);
        CollapsingToolbarLayout collapsingToolbarLayout = findViewById(R.id.collapsingToolbarLayout);

        priceViewnum = findViewById(R.id.priceViewnum);
        introduceView = findViewById(R.id.introduceView);
        shaidanView = findViewById(R.id.shaidanView);
        detailView = findViewById(R.id.detailView);
        productTuijianView = findViewById(R.id.productTuijianView);

        svscrollouter = findViewById(R.id.nestedScrollView);

        tv_name = findViewById(R.id.tv_name);
        tv_price = findViewById(R.id.tv_price);
        tv_price_two = findViewById(R.id.tv_price_two);
        iv_kefu = findViewById(R.id.iv_kefu);
        tv_price_two.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG );
        appBarlayout.clearAnimation();
        collapsingToolbarLayout.clearAnimation();

        iv_share = findViewById(R.id.iv_share);
        iv_gwc = findViewById(R.id.iv_gwc);
        iv_xyd = findViewById(R.id.iv_xyd);
        iv_share.setOnClickListener(this);
        iv_gwc.setOnClickListener(this);
        findViewById(R.id.tv_buy).setOnClickListener(this);
        findViewById(R.id.tv_join_gwc).setOnClickListener(this);
        setXyd();//设置心愿单
        initBanne2();
        initBottom();

        jumpKefu();
    }

    private void jumpKefu() {
        iv_kefu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.e("@@@@","AAAAA"+ChatClient.getInstance().isLoggedInBefore());
                if(ChatClient.getInstance().isLoggedInBefore()){
                    //已经登录，可以直接进入会话界面
                    Log.e("@@@@","BBBBBB");
                    System.out.println();
                    Intent intent = new IntentBuilder(context)
                            .setServiceIMNumber("gemmekefu") //获取地址：kefu.easemob.com，“管理员模式 > 渠道管理 > 手机APP”页面的关联的“IM服务号”
                            .build();
                    startActivity(intent);
                }else{
                    //未登录，需要登录后，再进入会话界面
                    Log.e("@@@@","CCCCCCC");
                    System.out.println();
                }
            }
        });
    }


    private void initBottom() {
        introduceView.initData(id);
        shaidanView.initData(id);
        detailView.initData(id);
        productTuijianView.initData(brandId);
    }

    private void initBanne2() {
        ImageView iv_banne_1 = findViewById(R.id.iv_banne_1);
        ImageView iv_banne_2 = findViewById(R.id.iv_banne_2);
        ImageView iv_banne_3 = findViewById(R.id.iv_banne_3);
        ImageView iv_banne_4 = findViewById(R.id.iv_banne_4);
        iv_banne_1.setVisibility(View.GONE);
        iv_banne_2.setVisibility(View.GONE);
        iv_banne_3.setVisibility(View.GONE);
        iv_banne_4.setVisibility(View.GONE);
        try {
            for (int i = 0; i < picList.size(); i++) {
                if(TextUtils.isEmpty(picList.get(i)))
                    return;
                if(i == 0){
                    iv_banne_1.setVisibility(View.VISIBLE);
                    Glide.with(context).load(picList.get(i))
                            .transform(new GlideRoundTransform(5)) //圆角
                            .into(iv_banne_1);
                } if(i == 1){
                    iv_banne_2.setVisibility(View.VISIBLE);
                    Glide.with(context).load(picList.get(i))
                            .transform(new GlideRoundTransform(5)) //圆角
                            .into(iv_banne_2);
                } if(i == 2){
                    iv_banne_3.setVisibility(View.VISIBLE);
                    Glide.with(context).load(picList.get(i))
                            .transform(new GlideRoundTransform(5)) //圆角
                            .into(iv_banne_3);
                } if(i == 3){
                    iv_banne_4.setVisibility(View.VISIBLE);
                    Glide.with(context).load(picList.get(i))
                            .transform(new GlideRoundTransform(5)) //圆角
                            .into(iv_banne_4);
                }
            }
        }catch (Exception e){

        }
    }

    TabLayout mTabLayout;
    ArrayList<String> tab_list = new ArrayList<>();
    private void initTabLayout() {
        mTabLayout = findViewById(R.id.tablayout);
        tab_list.add("商品");
        tab_list.add("晒单");
        tab_list.add("详情");
        tab_list.add("推荐");

        for (int i = 0; i < tab_list.size(); i++) {
            mTabLayout.addTab(mTabLayout.newTab().setText(tab_list.get(i) + ""));
        }

        mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener(){

            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                if("-1".equals(tab.getTag())){
                    tab.setTag("0");
                    return;
                }
                selectTab(tab);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                System.out.println();
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
                System.out.println();
            }
        });
    }


    private void initTop() {
      /*  StatusBarUtil.setTransparent(this);
//        StatusBarUtil.setTranslucent(this);
        setAndroidNativeLightStatusBar(this,false);*/
       findViewById(R.id.arrow_left).setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               finish();
           }
       });
    }


    List<String> picList;//轮播图数据
    List<AttributeSpecListBean> attributeSpecListBeans;//属性弹窗数据
    ProductBean productBean;
    private void initData() {
        if(id <=  -1)
            return;
        String url = DataManager.BaseUrl_weicheng + "mall/shopsku/findSku?id=" + id;
        HashMap<String, String> headHashMap = new HashMap<>();
        headHashMap.put(DataManager.AuthorizationKey,DataManager.getToken(this));
        DataManager.toServer2(this, url, DataManager.GET_TYPE, "", headHashMap, new DataManager.GeResponse(){

            @Override
            public void onResponse(String response) {

                try {
                    System.out.println("");
//

                    productBean = JSON.parseObject(response, ProductBean.class);

//                    tv_name.setText(productBean.getData().get(0).getShopBrandInfoPojo().getBrandName() + "");
                    tv_name.setText(productBean.getData().get(0).getShopProductInfoPojo().getProductName() + "");

                   /* double activityPrice = productBean.getData().get(0).getActivityPrice();
                    int attributeSpecPrice = productBean.getData().get(0).getAttributeSpecPrice();
                    tv_price.setText("¥ " + activityPrice + "");
                    tv_price_two.setText("¥ " + attributeSpecPrice + "");
                    if(activityPrice <= 0 && attributeSpecPrice > 0){
                        tv_price.setText("¥ " + attributeSpecPrice + "");
                    }*/
                    BigDecimal price = StrUtil.toBigDecimal(productBean.getData().get(0).getPrice());
                    String productPrice = StrUtil.noNUll(productBean.getData().get(0).getProductPrice());
                    tv_price.setText(TextUtils.isEmpty(productPrice) ?  price+ "" : productPrice + "");
                    tv_price_two.setText(price + "");



                    picList = productBean.getData().get(0).getShopProductPicturePojo().getPicList();
                    if(picList != null){
                        initBanner();
                        initBanne2();
                    }

//                    String attributeSpecList = productBean.getData().get(0).getAttributeSpecList();
                    String s = productBean.getData().get(0).getAttributeSpecList().replaceAll("\"", "\"");

                    attributeSpecListBeans = JSON.parseArray(s, AttributeSpecListBean.class);
                    System.out.println("");

                }catch (Exception e){

                }
            }
        });
    }


    public void getAndroiodScreenProperty() {
        WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics dm = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(dm);
        int width = dm.widthPixels;         // 屏幕宽度（像素）
        int height = dm.heightPixels;       // 屏幕高度（像素）
        float density = dm.density;         // 屏幕密度（0.75 / 1.0 / 1.5）
        int densityDpi = dm.densityDpi;     // 屏幕密度dpi（120 / 160 / 240）
        // 屏幕宽度算法:屏幕宽度（像素）/屏幕密度
        int screenWidth = (int) (width / density);  // 屏幕宽度(dp)
        int screenHeight = (int) (height / density);// 屏幕高度(dp)


        Log.d("h_bl", "屏幕宽度（像素）：" + width);
        Log.d("h_bl", "屏幕高度（像素）：" + height);
        Log.d("h_bl", "屏幕密度（0.75 / 1.0 / 1.5）：" + density);
        Log.d("h_bl", "屏幕密度dpi（120 / 160 / 240）：" + densityDpi);
        Log.d("h_bl", "屏幕宽度（dp）：" + screenWidth);
        Log.d("h_bl", "屏幕高度（dp）：" + screenHeight);
    }

    int select = -1;
    private void controlScroll() {

        svscrollouter.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                int viewVisible = getViewVisible();
                if (select == viewVisible)
                    return false;
                System.out.println("toTab : " + viewVisible);
                toTab(viewVisible);
                select = viewVisible;
                return false;
            }
        });
    }

    private int getViewVisible() {
        int tab = 0;
        //判断某个控件是否可见
        Rect scrollBounds = new Rect();
        svscrollouter.getHitRect(scrollBounds);
        if (introduceView.getLocalVisibleRect(scrollBounds)) {//可见
            Log.e(TAG, "introduceView:  可见" );
            return 0;
        }
        if (shaidanView.getLocalVisibleRect(scrollBounds)) {//可见
            Log.e(TAG, "shaidanView:  可见" );
            return 1;
        }


        if (productTuijianView.getLocalVisibleRect(scrollBounds)) {//可见
            Log.e(TAG, "productTuijianView:  可见" );
            return 3;
        }

        if (detailView.getLocalVisibleRect(scrollBounds)) {//可见
            Log.e(TAG, "detailView:  可见" );
           return 2;
        }



       return  tab;
    }

    private void toTab(int i) {
        try {
            TabLayout.Tab tabAt = mTabLayout.getTabAt(i);
            tabAt.setTag("-1");
            mTabLayout.selectTab(tabAt);

        }catch (Exception e){

        }
    }

    private void selectTab(TabLayout.Tab tab) {
        int i = tab.getPosition();
        try {
            TabLayout.Tab tabAt = mTabLayout.getTabAt(i);
            mTabLayout.selectTab(tabAt);
            switch (i){
                case 0:
                    svscrollouter.scrollTo(0,introduceView.getTop());
                    break;
                case 1:
                    svscrollouter.scrollTo(0,shaidanView.getTop());
                    break;
                case 2:
                    svscrollouter.scrollTo(0,detailView.getTop());
                    break;
                case 3:
                    svscrollouter.scrollTo(0,productTuijianView.getTop());
                    break;


            }


        }catch (Exception e){

        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.iv_share:
                ShareDialog shareDialog = new ShareDialog();
                shareDialog.showDialog(ProductNewActivity.this);
                String imageStr = null;
                if (dataBeans != null && dataBeans.size() > 0){

                    imageStr = dataBeans.get(0).getImageRes();
                }

                shareDialog.setData(imageStr,"http://www.ahkuayu.com/",
                        tv_name.getText() + "",tv_name.getText() + "");
                break;

            case R.id.iv_gwc: //购物车
                finish();
                MainActivity.getTabUI().setTab(2);
                break;

            case R.id.tv_buy:
                guigeDialog = new GuigeDialog();
                guigeDialog.showDialog(ProductNewActivity.this,productBean.getData().get(0).getShopProductInfoPojo().getProductName() );
                guigeDialog.setData(attributeSpecListBeans);
                guigeDialog.setOnSelectReturn(new GuigeSingleView.OnSelectReturn() {
                    @Override
                    public void OnSelectReturn(AttributeSpecListBean bean, int num) {
                        try {
                            tv_name.setText(getName(bean) + "");
                            tv_price.setText(bean.getDiscountPrice() <= 0 ?  bean.getAttributeSpecPrice() : bean.getDiscountPrice() + "");
                            tv_price_two.setText(bean.getAttributeSpecPrice());
                            priceViewnum.setNum(num);
                            guigeDialog.dismiss();


                            submitDingdan(bean,num);

                        }catch (Exception e){

                        }
                    }
                });
                break;

            case R.id.tv_join_gwc:
                guigeDialog = new GuigeDialog();
                guigeDialog.showDialog(ProductNewActivity.this,productBean.getData().get(0).getShopProductInfoPojo().getProductName() );
                guigeDialog.setData(attributeSpecListBeans);
                guigeDialog.setOnSelectReturn(new GuigeSingleView.OnSelectReturn() {
                    @Override
                    public void OnSelectReturn(AttributeSpecListBean bean, int num) {
                        try {
                            tv_name.setText(getName(bean) + "");
                            tv_price.setText(bean.getDiscountPrice() <= 0 ?  bean.getAttributeSpecPrice() : bean.getDiscountPrice() + "");
                            tv_price_two.setText(bean.getAttributeSpecPrice());
                            priceViewnum.setNum(num);
                            guigeDialog.dismiss();


//                            submitDingdan(bean,num);

                            addGwc(bean,num);

                        }catch (Exception e){

                        }
                    }
                });
                break;

        }
    }

    private void submitDingdan(AttributeSpecListBean bean, int num) {
        if(id <  -1)
            id = bean.getProductId();
        if(id <  -1){
            Toast.makeText(context, "商品信息为空", Toast.LENGTH_SHORT).show();
            return;
        }




//        http://192.168.1.7:9999/mall/shoporder/getShopDiscountCouponsPage?cardProductId=24,f319cd38-3cf2-8a79-eefa-65747aa9c0f1,1
       /* String url = DataManager.BaseUrl + ":9999/mall/shoporder/getShopDiscountCouponsPage?cardProductId=" +
                bean.getProductId() + "," + bean.getUuid() + "," + num
                ;*/

        String url = DataManager.BaseUrl + "mall/shoporder/getShopDiscountCouponsPage?cardProductId=" +
                id + "," + bean.getUuid() + "," + num
                ;
        HashMap<String, String> headMap = new HashMap<>();
        headMap.put(DataManager.AuthorizationKey,DataManager.getToken(context));
//        headMap.put(DataManager.AuthorizationKey,"Bearer 2af9350c-dad4-4e04-b5b9-6a931f9b7b0c");
        DataManager.toServer3(context, url, DataManager.GET_TYPE, "", headMap, new DataManager.GeResponse() {
            @Override
            public void onResponse(String response) {
                try{
                    System.out.println("");
                    Intent intent = new Intent(context, ConfirmOrderActivity.class);
                    intent.putExtra("data",response);
                    intent.putExtra("id",id);

                    startActivity(intent);


                }catch (Exception e){

                }
            }
        });
    }


    private String getName(AttributeSpecListBean bean) {
        String name= "";
        try {
            List<AttributeSpecListBean.PropertyListBean> propertyList = bean.getPropertyList();
            for (int i = 0; i < propertyList.size(); i++) {
                AttributeSpecListBean.PropertyListBean pBean = propertyList.get(i);
                String attributeName = pBean.getAttributeName();
                String attributeSpecName = pBean.getAttributeSpecName();

                if(TextUtils.isEmpty(name)){
                    name = name + attributeName +"+"+ attributeSpecName;
                }else{
                    name = name +"+"+ attributeName +"+"+ attributeSpecName;
                }

            }
        }catch (Exception e){

        }

        return name;
    }

/*
    private void testAddGwc(AttributeSpecListBean bean, int num) {
        if(id <  -1)
            id = bean.getProductId();
        if(id <  -1){
            Toast.makeText(context, "商品信息为空", Toast.LENGTH_SHORT).show();
            return;
        }
//        http://192.168.1.9:9999/mall/shopordercart/saveShopOrderCart?
        String url = DataManager.BaseUrl_weicheng + ":9999/mall/shopordercart/saveShopOrderCart";
        AddGwcBean addGwcBean = new AddGwcBean();
        addGwcBean.setId(null);
        addGwcBean.setUserId(25L);//用户id
        addGwcBean.setProductId(25L);//商品id
        addGwcBean.setProductAmount(2);//加入购物车商品数量
        addGwcBean.setPrice(null);//商品金额
        addGwcBean.setAttributeName(null);//规格参数
        addGwcBean.setAttributeId("a1d71b57-4165-88c3-b786-69b4b799bb0f");//规格id
        addGwcBean.setActivityId(null);//活动id
        addGwcBean.setCreateTime(null);//加入购物车时间
        addGwcBean.setCreateBy(null);//创建者
        addGwcBean.setUpdateTime(null);//最后修改时间
        addGwcBean.setUpdateBy(null);//更新者
        addGwcBean.setRemarks(null);//备注信息
        addGwcBean.setParameterList(null);//参数集合

        Gson gson = new Gson();
        String jsonString = JSON.toJSONString(addGwcBean);
        String strJson = gson.toJson(addGwcBean);


        System.out.println("weixinlogin url :   " + url);
        HashMap<String, String> headMap = new HashMap<>();
        headMap.put("Authorization",DataManager.getToken(this));
        DataManager.toServer3(context, url, DataManager.POST_TYPE, jsonString, headMap, new DataManager.GeResponse() {
            @Override
            public void onResponse(String response) {
                try{
                    System.out.println("");
                }catch (Exception e){

                }
            }
        });
    }
*/


/*
    private void addGwc(AttributeSpecListBean bean, int num) {
        try {
            if(id <  -1)
                id = bean.getProductId();
            if(id <  -1){
                Toast.makeText(context, "商品信息为空", Toast.LENGTH_SHORT).show();
                return;
            }

            String userIdstr = SPUtil.getDataForString(context, Constant.UserId, "");

            if(TextUtils.isEmpty(userIdstr)){
                Toast.makeText(context, "加入购物车失败", Toast.LENGTH_SHORT).show();
                return;
            }

            if(num < 0){
                Toast.makeText(context, "商品数量不能小于0", Toast.LENGTH_SHORT).show();
                return;
            }

            Long userId = Long.parseLong(userIdstr);


//        http://192.168.1.9:9999/mall/shopordercart/saveShopOrderCart?
            String url = DataManager.BaseUrl_weicheng + ":9999/mall/shopordercart/saveShopOrderCart";
            AddGwcBean addGwcBean = new AddGwcBean();
            addGwcBean.setId(null);
            addGwcBean.setUserId(userId);//用户id
            addGwcBean.setProductId(id);//商品id
            addGwcBean.setProductAmount(num);//加入购物车商品数量
            addGwcBean.setPrice(new BigDecimal(tv_price.getText() + ""));//商品金额
            addGwcBean.setAttributeName(tv_name.getText() + "");//规格参数
            addGwcBean.setAttributeId(bean.getUuid());//规格id
            addGwcBean.setActivityId(null);//活动id
            addGwcBean.setCreateTime(null);//加入购物车时间
            addGwcBean.setCreateBy(null);//创建者
            addGwcBean.setUpdateTime(null);//最后修改时间
            addGwcBean.setUpdateBy(null);//更新者
            addGwcBean.setRemarks(null);//备注信息
            addGwcBean.setParameterList(null);//参数集合

            Gson gson = new Gson();
            String jsonString = JSON.toJSONString(addGwcBean);
            String strJson = gson.toJson(addGwcBean);


            System.out.println("weixinlogin url :   " + url);
            HashMap<String, String> headMap = new HashMap<>();
            headMap.put("Authorization",DataManager.getToken(this));
            DataManager.toServer3(context, url, DataManager.POST_TYPE, jsonString, headMap, new DataManager.GeResponse() {
                @Override
                public void onResponse(String response) {
                    try{
                        System.out.println("");

                    }catch (Exception e){

                    }
                }
            });
        }catch (Exception e){

        }
    }
*/


    private void addGwc(AttributeSpecListBean bean, int num) {
        try {
            if(id <  -1)
                id = bean.getProductId();
            if(id <  -1){
                Toast.makeText(context, "商品信息为空", Toast.LENGTH_SHORT).show();
                return;
            }

            String userIdstr = SPUtil.getDataForString(context, Constant.UserId, "");

            if(TextUtils.isEmpty(userIdstr)){
                Toast.makeText(context, "加入购物车失败", Toast.LENGTH_SHORT).show();
                return;
            }

            if(num < 0){
                Toast.makeText(context, "商品数量不能小于0", Toast.LENGTH_SHORT).show();
                return;
            }

            Long userId = Long.parseLong(userIdstr);

//            http://192.168.1.10:9999/mall/shopordercart/saveShopOrderCart?userId=82&productId=31&productAmount=2&
//            price=2325&attributeId=926468c5-705e-0bb8-90d5-8ee6b086dcff&attributeName=净含量+滋润age 100g
            String url = DataManager.BaseUrl_weicheng + "mall/shopordercart/saveShopOrderCart?" +
                    "userId=" + userId+
                    "&productId=" + id +
                    "&productAmount=" + num +
                    "&price=" + new BigDecimal(tv_price.getText() + "") +
                    "&attributeId=" + bean.getUuid() +
                    "&attributeName=" + tv_name.getText() + "" +
                    "&specValue=" + tv_name.getText() + "" +
                    "&attrUuid=" + bean.getUuid() + "" +
                    "&pictureUrl=" + bean.getAttributeSpecImage() + ""
                    ;


            HashMap<String, String> headMap = new HashMap<>();
            headMap.put("Authorization",DataManager.getToken(this));
            DataManager.toServer3(context, url, DataManager.POST_TYPE, "", headMap, new DataManager.GeResponse() {
                @Override
                public void onResponse(String response) {
                    try{
                        System.out.println("");
                        if(DataPares.isSucess(context,response)){
                            Toast.makeText(context, "加入购物车成功", Toast.LENGTH_SHORT).show();
                        }
                    }catch (Exception e){

                    }
                }
            });
        }catch (Exception e){

        }
    }


    boolean isXyd = false;
    private void setXyd() {
        changeXyd();
        iv_xyd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                isXyd = !isXyd;
                changeXyd();
                if(isXyd){
                    addXyd();
                }
            }
        });
    }

    private void addXyd() {
       try {
           String url = DataManager.BaseUrl + "mall/shopwish/app/add?productId=" + id;

           HashMap<String, String> headMap = new HashMap<>();
           headMap.put("Authorization",DataManager.getToken(this));
           DataManager.toServer3(context, url, DataManager.GET_TYPE, "", headMap, new DataManager.GeResponse() {
               @Override
               public void onResponse(String response) {
                   try{
                       System.out.println("");

                       if(DataPares.isSucess(context,response)){
                           Toast.makeText(context, "添加成功！", Toast.LENGTH_SHORT).show();
                       }else{
                           Toast.makeText(context, "添加失败！", Toast.LENGTH_SHORT).show();
                       }
                       
                   }catch (Exception e){

                   }
               }
           });
       }catch (Exception e){

       }
    }

    public void changeXyd(){
        if(isXyd){
            iv_xyd.setBackgroundResource(R.drawable.wish_list);
        }else{
            iv_xyd.setBackgroundResource(R.drawable.pc_wish_no_list);
        }
    }

}




